

function myaxios(config){
    console.log(config);
    const {url,method,data,params}=config

    return new Promise((resolve,reject)=>{
const xhr = new XMLHttpRequest()
 if (method.toUpperCase()==='GET') {
    const P =getParams(params)
    console.log(P);
    xhr.open('GET',params?url+'?'+P:url)
    xhr.send()
 }else{
    xhr.open('POST',url)
    const flag = Object.prototype.toString.call(data)==='[object Object]'
    xhr.setRequestHeader('Content-Type','application/json')
    xhr.send(flag?JSON.stringify(data):data)
 }
   
    xhr.onreadystatechange=function(){
        if (xhr.readyState===4) {
            if (xhr.status>=200&&xhr.status<300) {
                return resolve(JSON.parse(xhr.responseText))
            }else{
                return reject('错了，原因是'+xhr.status)
            }
        }
    }
    })
}


const getParams=function(obj){
    const arr = []
    for(let k in obj){
       arr.push(k+'='+obj[k])
    }
    return arr.join('&')

}
